package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.sysrole.SysRoleDO;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysRoleService;
import com.example.demo.dto.sysrole.SysRolePageReqVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping(value = "/system/role")
@RestController
public class SysRoleController extends BaseAdminController {

    @Resource
    private ISysRoleService sysRoleService;

    @GetMapping("/list")
    public AjaxRes list(SysRolePageReqVO sysRolePageReqVO) {
        return AjaxRes.success(sysRoleService.list(sysRolePageReqVO));
    }

    @PostMapping("/insert")
    @Log(title = "新增角色", businessType = BusinessType.INSERT)
    public AjaxRes insert(@RequestBody SysRoleDO sysRoleDO) {
        return toAjax(sysRoleService.addSysRole(sysRoleDO));
    }

    @DeleteMapping("/delete/{roleId}")
    @Log(title = "删除角色", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("roleId") Long roleId) {
        return toAjax(sysRoleService.deleteSysRole(new SysRoleDO().setId(roleId)));
    }

    @PutMapping("/update")
    @Log(title = "更新角色", businessType = BusinessType.UPDATE)
    public AjaxRes update(@RequestBody SysRoleDO sysRoleDO) {
        return toAjax(sysRoleService.updateSysRole(sysRoleDO));
    }

    @GetMapping("/{roleId}")
    public AjaxRes query(@PathVariable("roleId") Long roleId) {
        return AjaxRes.success(sysRoleService.getSysRole(new SysRoleDO().setId(roleId)));
    }
}
